import openpyxl

def extract_columns_to_text_files(filename):
    # 加载电子表格文件
    workbook = openpyxl.load_workbook(filename)

    # 遍历所有工作表
    for sheet in workbook:
        # 创建对应列的文本文件
        for column in range(1, sheet.max_column + 1):
            column_values = []
            for row in range(1, sheet.max_row + 1):
                cell_value = sheet.cell(row=row, column=column).value
                if cell_value:
                    column_values.append(str(cell_value))

            # 写入文本文件
            if column_values:
                output_filename = f"column_{column}.txt"
                with open(output_filename, "w") as file:
                    file.write("\n".join(column_values))

                print(f"列 {column} 的内容已写入到文件：{output_filename}")

    workbook.close()

if __name__ == "__main__":
    filename = input("请输入电子表格文件的路径：")
    extract_columns_to_text_files(filename)